//
//  Person.m
//  05-Homework
//
//  Created by Snow on 16/7/8.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "Person.h"

@implementation Person
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender
{
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _gender = gender;
    }
    return self;
}
+ (instancetype)personWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender
{
    return [[Person alloc]initWithName:name age:age gender:gender];
}
- (NSComparisonResult)compareByName:(Person *)person
{
    return [self.name compare:person.name];
}
- (NSComparisonResult)compareByGender:(Person *)person
{
    return [self.gender compare:person.gender];
}
- (NSComparisonResult)compareByAge:(Person *)person
{
    if (self.age > person.age) {
        return NSOrderedAscending;
    } else if (self.age == person.age) {
        return NSOrderedSame;
    } else {
        return NSOrderedDescending;
    }
}
@end
